import MySQLdb
import MySQLdb.cursors

host = "localhost"
user = "root"
passwd = "root"
db_name = "erpsussan"

db=MySQLdb.connect(host=host,user=user,passwd=passwd,db=db_name, cursorclass=MySQLdb.cursors.DictCursor)
c=db.cursor()
sql = "SELECT * FROM stock_cargar WHERE sucursal = '1'"
c.execute(sql)

file = open("stock.csv", "w+")

i = 0
for f in c:
    #print "STOCK = " , int(f['stock'])
    for ptc in range(int(f['stock'])):
        i += 1
        print f['ptc']
        file.write(f['ptc'] + ";\r\n")
        
file.close()